﻿using System;
using System.Windows;
using System.Windows.Input;
using YSGetLatest.DataObjects;
using YSGetLatest.ViewModels;
using System.ComponentModel;

namespace YSGetLatest
{
	/// <summary>
	/// Interaction logic for ProjectWindow.xaml
	/// </summary>
	public partial class ProjectWindow : Window
	{
		#region Properties

		/// <summary>
		/// Gets the ProjectWindowViewModel.
		/// </summary>
		public ProjectWindowViewModel ProjectWindowViewModel
		{
			get;
			private set;
		}
		#endregion

		#region Constructor

		/// <summary>
		/// Initializes a new instance of the ProjectWindow class.
		/// </summary>
		/// <param name="project">Specifies the Project.</param>
		public ProjectWindow(Project project)
		{
			if (project == null)
			{
				throw new ArgumentNullException("project");
			}
			InitializeComponent();

			ProjectWindowViewModel = new ProjectWindowViewModel(this, listViewFolders, 
				progressBarStatus, statusBarItemProgressBar, textBlockFolderNameStatus, 
				textBlockStatus, project);

			DataContext = ProjectWindowViewModel;
		}
		#endregion

		#region Methods

		private void ListViewProjects_MouseDoubleClick(object sender, MouseButtonEventArgs e)
		{
			if (ProjectWindowViewModel.EditFolderCommand.CanExecute(e))
			{
				ProjectWindowViewModel.EditFolderCommand.Execute(e);
			}
		}

		private void CheckBox_Checked(object sender, RoutedEventArgs e)
		{
			ProjectWindowViewModel.EnabledChanged(sender);
		}

		private void Window_Closing(object sender, CancelEventArgs e)
		{
			e.Cancel = !ProjectWindowViewModel.CanClose;
		}
		#endregion
	}
}
